﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.person_info
{
    public partial class personality : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                for (int i = 1; i < 27; i++)
                {
                    ListItem item = new ListItem();
                    item.Value = i.ToString();
                    item.Text = "<IMG src=\"/images/avatar/" + i.ToString() + ".gif\">&nbsp;&nbsp;";
                    this.rblAvatar.Items.Add(item);
                }
                DataSet set = new DataSet();
                //set.ReadXml(Server.MapPath("/theme2009/theme.xml"));
                //this.ddlTheme.DataSource = set.Tables["Theme"];
                //this.ddlTheme.DataValueField = "Id";
                //this.ddlTheme.DataTextField = "Name";
                //this.ddlTheme.DataBind();
                set = new DataSet();
                set.ReadXml(Server.MapPath("/callsound/callsound.xml"));
                this.ddlCallSound.DataSource = set.Tables["CallSound"];
                this.ddlCallSound.DataValueField = "Id";
                this.ddlCallSound.DataTextField = "Name";
                this.ddlCallSound.DataBind();
                this.ddlCallSound.Items.Add(new ListItem("无", "0"));
                DataTable table = new UsersDao().SelectByUserId(base.Conn, base.User.Identity.Name);
                if (table.Rows.Count > 0)
                {
                    this.txtNickName.Text = (table.Rows[0]["NickName"] != DBNull.Value) ? table.Rows[0]["NickName"].ToString() : "";
                    if (this.rblAvatar.Items.FindByValue(table.Rows[0]["Avatar"].ToString()) != null)
                    {
                        this.rblAvatar.Items.FindByValue(table.Rows[0]["Avatar"].ToString()).Selected = true;
                    }
                    else
                    {
                        this.rblAvatar.Items.FindByValue("1").Selected = true;
                    }
                    //if (this.ddlTheme.Items.FindByValue(table.Rows[0]["Theme"].ToString()) != null)
                    //{
                    //    this.ddlTheme.Items.FindByValue(table.Rows[0]["Theme"].ToString()).Selected = true;
                    //}
                    this.ddlMenuType.Items.FindByValue(table.Rows[0]["MenuType"].ToString()).Selected = true;
                    this.ddlMenuHide.Items.FindByValue(table.Rows[0]["MenuHide"].ToString()).Selected = true;
                    this.ddlSmsOn.Items.FindByValue(table.Rows[0]["SmsOn"].ToString()).Selected = true;
                    if (this.ddlCallSound.Items.FindByValue(table.Rows[0]["CallSound"].ToString()) != null)
                    {
                        this.ddlCallSound.Items.FindByValue(table.Rows[0]["CallSound"].ToString()).Selected = true;
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                UsersDao dao2 = new UsersDao();
                UsersData data = new UsersData();
                data.UserId = base.User.Identity.Name;
                data.NickName = this.txtNickName.Text;
                data.Avatar = Convert.ToInt32(this.rblAvatar.SelectedValue);
                data.Theme = 1;
                data.MenuType = Convert.ToBoolean(this.ddlMenuType.SelectedValue);
                data.MenuHide = Convert.ToBoolean(this.ddlMenuHide.SelectedValue);
                data.SmsOn = Convert.ToBoolean(this.ddlSmsOn.SelectedValue);
                data.CallSound = Convert.ToInt32(this.ddlCallSound.SelectedValue);
                dao2.UpdatePersonality(base.Conn, data);
                UserCache.Update(base.User.Identity.Name);
                this.litMessage.Text = base.ShowPrompt("个性设置修改成功！", "index.aspx");
            }
        } 

    }
}
